package introse;

public class client {
    private int clientNumber;
    private String clientName;
    private String clientAddress;
    private int contactNumber;
    private boolean isActive;
    
    public client(int clientNumber, String clientName, String clientAddress, int contactNumber, boolean isActive){
        this.clientNumber = clientNumber;
        this.clientName = clientName;
        this.clientAddress = clientAddress;
        this.contactNumber = contactNumber;
        this.isActive = isActive;
    }
    public int getClientNumber(){
        return clientNumber;
    }
    public String getClientName(){
        return clientName;
    }
    public String getClientAddress(){
        return clientAddress;
    }
    public int getContactNumber(){
        return contactNumber;
    }
    public boolean getIsActive(){
        return isActive;
    }
    
    public boolean setName(String clientName){
        databaseConn conn = new databaseConn();
        if(conn.sqlStatement(String.format("UPDATE `sashmirgasul`.`client` SET `clientName`='%s' WHERE `clientNumber`='%d';", clientName, this.getClientNumber()))){
            this.clientName = clientName;
            return true;
        }
        else{
            return false;
        }
    }
    
    public boolean setContactNumber(int contactNumber){
        databaseConn conn = new databaseConn();
        if(conn.sqlStatement(String.format("UPDATE `sashmirgasul`.`client` SET `contactNumber`='%s' WHERE `clientNumber`='%d';", contactNumber, this.getClientNumber()))){
            this.contactNumber = contactNumber;
            return true;
        }
        else{
            return false;
        }
    }
    
    public boolean setClientAddress(String clientAddress){
        databaseConn conn = new databaseConn();
        if(conn.sqlStatement(String.format("UPDATE `sashmirgasul`.`client` SET `clientAddress`='%s' WHERE `clientNumber`='%d';", clientAddress, this.getClientNumber()))){
            this.clientAddress = clientAddress;
            return true;
        }
        else{
            return false;
        }
    }
    
    public boolean setIsActive(boolean isActive){
        databaseConn conn = new databaseConn();
        if(conn.sqlStatement(String.format("UPDATE `sashmirgasul`.`client` SET `isActive`=%d WHERE `clientNumber`='%d';", isActive? 1 : 0, this.getClientNumber()))){
            this.isActive = isActive;
            return true;
        }
        else{
            return false;
        }
    }
}
